package com.hyt.it.ogt.kq.main.controller.gov;


import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.exception.exception.BusinessLogicException;
import com.hyt.it.ogt.kq.common.config.exception.KqException;
import com.hyt.it.ogt.kq.common.exception.GovInvalidRequestException;
import com.hyt.it.ogt.kq.common.gov.config.arrange.CommonLockKeyCreator;
import com.hyt.it.ogt.kq.common.gov.constant.ResponseCode;
import com.hyt.it.ogt.kq.common.gov.utils.TextUtil;
import com.hyt.it.ogt.kq.main.controller.base.BaseController;
import com.hyt.it.ogt.kq.service.gov.model.TaskSubjectImportDTO;
import com.hyt.it.ogt.kq.service.gov.model.dto.ExamSubjectDTO;
import com.hyt.it.ogt.kq.service.gov.model.dto.TaskTimeSubjectArrangeDTO;
import com.hyt.it.ogt.kq.service.gov.model.dto.TimeSubjectBindingDTO;
import com.hyt.it.ogt.kq.service.gov.model.param.ExamSubjectParam;
import com.hyt.it.ogt.kq.service.gov.model.param.SubjectDeleteParam;
import com.hyt.it.ogt.kq.service.gov.model.param.SubjectParam;
import com.hyt.it.ogt.kq.service.gov.service.*;
import com.hyt.it.ogt.kq.service.model.entity.Subject;
import com.hyt.log.annotation.Log;
import com.hyt.loginfo.model.User;
import com.hyt.model.PageParam;
import com.hyt.progress.creator.anno.ProgressAnno;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiSort;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.net.URLEncoder;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 科目信息表 前端控制器
 * </p>
 *
 * @author huangyh
 * @since 2021-03-08
 */
@RestController
@Api(tags = "104.科目接口", value = "科目接口")
@ApiSort(value = 104)
@RequestMapping("/kw/gov/subject")
@Slf4j
public class SubjectController extends BaseController {

    @Autowired
    private ISubjectService iSubjectService;

    @Autowired
    private ITimeSubjectService iTimeSubjectService;

    @Resource
    private ICandidateSubjectService iCandidateSubjectService;

    @Resource
    private ITaskService iTaskService;

    @Resource
    private ITaskRoomService iTaskRoomService;

    @ApiOperation(
            value = "4.1 根据考试任务id查询科目",
            notes = "30000:根据考试任务id查询科目成功; 30073:根据考试任务id查询科目异常; 30033:考试任务id不能为空"
    )
    @ApiOperationSort(value = 1)
    @RequestMapping(value = "/getSubjectByTaskId", method = RequestMethod.GET)
    public ApiResponse<Object> getSubjectByTaskId(String taskId) {

        log.info("# 根据考试任务id查询科目参数 ： {}", taskId);
        try {
            if (StringUtils.isEmpty(taskId)) {
                //考试任务id不能为空
                return ApiResponse.builder()
                        .code(ResponseCode.TASK_ID_ISNULL_OR_EXIST.getCode())
                        .build();
            }
            List<Subject> subjectList = iSubjectService.getSubjectByTaskId(taskId);
            return ApiResponse.builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .data(subjectList)
                    .build();
        } catch (Exception e) {
            log.error("# 根据考试任务id查询科目异常:", e);
            return ApiResponse.builder()
                    .code(ResponseCode.SUBJECT_QUERY_BY_TASK_ID_EXCEPTION.getCode())
                    .build();
        }
    }

    @ApiOperation(
            value = "4.2 添加科目",
            notes = "30000:添加科目成功; 30104:添加科目异常; 30105:添加科目参数校验错误; 30106:科目编号重复; 30107:科目名称重复; 30114:当前考试任务已不存在; 30115:科目时长必须为正整数; 30116:开考后允许交卷时间必须为非负整数; 30117:科目时长必须大于或等于考试任务配置的允许迟到分钟数; 30118:开考后允许交卷时间必须小于或等于科目时长; 30119:结束前提醒交卷时间必须小于或等于科目时长"
    )
    @ApiOperationSort(value = 2)
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ApiResponse<Object> add(@Valid @RequestBody SubjectParam subjectParam) {
        log.info("# 添加科目参数: {}", subjectParam.toString());
        User user = getUser();
        if (Objects.isNull(user) || Objects.isNull(user.getId())) {
            return ApiResponse.builder()
                    .code(ResponseCode.USER_NOT_LOGIN.getCode())
                    .build();
        }
        try {
            iSubjectService.add(subjectParam, user);
            return ApiResponse.builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .build();
        } catch (KqException k) {
            log.error("# 添加科目业务异常: {}", k.getErrMsg());
            return ApiResponse.builder()
                    .code(k.getErrCode())
                    .build();
        } catch (GovInvalidRequestException i) {
            log.error("# 添加科目业务异常: {}", i.getMessage());
            return ApiResponse.builder()
                    .code(i.getCode())
                    .build();
        } catch (Exception e) {
            log.error("# 添加科目异常: ", e);
            return ApiResponse.builder()
                    .code(ResponseCode.SUBJECT_ADD_EXCEPTION.getCode())
                    .build();
        }
    }

    @ApiOperation(
            value = "4.3 修改科目",
            notes = "30000:修改科目成功; 30104:修改科目异常; 30105:修改科目参数校验错误; 30106:科目编号重复; 30107:科目名称重复; 30114:当前考试任务已不存在; 30115:科目时长必须为正整数; 30116:开考后允许交卷时间必须为非负整数; 30117:科目时长必须大于或等于考试任务配置的允许迟到分钟数; 30118:开考后允许交卷时间必须小于或等于科目时长; " +
                    "30119:结束前提醒交卷时间必须小于或等于科目时长；30300：科目已绑定批次，不允许变更"
    )
    @ApiOperationSort(value = 3)
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ApiResponse<Object> update(@Valid @RequestBody SubjectParam subjectParam) {
        log.info("# 修改科目参数 ：{}", subjectParam.toString());
        User user = getUser();
        if (Objects.isNull(user) || Objects.isNull(user.getId())) {
            return ApiResponse.builder()
                    .code(ResponseCode.USER_NOT_LOGIN.getCode())
                    .build();
        }
        try {
            // 校验任务数据锁定状态(后续版本考虑优化为从缓存中获取状态)
            iTaskService.isLockDataThrowException(subjectParam.getTaskId());

            if (StringUtils.isEmpty(subjectParam.getId())) {
                //科目id不能为空
                return ApiResponse.builder()
                        .code(ResponseCode.SUBJECT_ID_IS_NULL.getCode())
                        .build();
            }
            // 检查是否绑定批次
            if (iTimeSubjectService.isTimeSubjectBinding(subjectParam.getTaskId(),
                    subjectParam.getId())) {
                return ApiResponse.builder()
                        .code(ResponseCode.SUBJECT_IS_BIND_FORBID_CHANGE.getCode())
                        .build();
            }
            Subject subject = new Subject();
            subject.setTaskId(subjectParam.getTaskId())
                    .setName(subjectParam.getName())
                    .setCode(subjectParam.getCode())
                    .setLength(StringUtils.isNotBlank(subjectParam.getLength()) ? NumberUtil.toBigDecimal(subjectParam.getLength()) : null)
                    .setHandInTime(StringUtils.isNotBlank(subjectParam.getHandInTime()) ? NumberUtil.toBigDecimal(subjectParam.getHandInTime()) : null)
                    .setRemindTime(StringUtils.isNotBlank(subjectParam.getRemindTime()) ? NumberUtil.toBigDecimal(subjectParam.getRemindTime()) : null)
                    .setId(subjectParam.getId());
            subject.setOfficeId(user.getOfficeid());
            subject.setDeptId(subjectParam.getDeptId());
            subject.setGrade(subjectParam.getGrade());
            subject.setRoomTypeId(subjectParam.getRoomTypeId());
            iSubjectService.checkSubjectRepeat(subject);
            iSubjectService.update(subject);

            //如果是绑定报名，则检测修复考生科目表中无code问题
            iCandidateSubjectService.checkCandidateSubjectUpdateSubjectCodeOrIdNumber(subject.getTaskId());

            return ApiResponse.builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .build();
        } catch (KqException k) {
            log.error("# 修改科目业务异常: {}", k.getErrMsg());
            return ApiResponse.builder()
                    .code(k.getErrCode())
                    .build();
        } catch (GovInvalidRequestException i) {
            log.error("# 修改科目异常: {}", i.getMessage());
            return ApiResponse.builder()
                    .code(i.getCode())
                    .build();
        } catch (Exception e) {
            log.error("# 修改科目异常:", e);
            return ApiResponse.builder()
                    .code(ResponseCode.SUBJECT_UPDATE_EXCEPTION.getCode())
                    .build();
        }
    }

    @ApiOperation(
            value = "4.4 根据id获取科目",
            notes = "30000:根据id获取科目成功; 30111:根据id获取科目异常; 30112:科目id不能为空; 30113:科目不存在"
    )
    @ApiOperationSort(value = 4)
    @RequestMapping(value = "/query", method = RequestMethod.GET)
    public ApiResponse<Object> query(String subjectId) {
        log.info("# 根据id获取科目参数： {}", subjectId);
        try {
            if (StringUtils.isEmpty(subjectId)) {
                //科目id不能为空
                return ApiResponse.builder()
                        .code(ResponseCode.SUBJECT_ID_IS_NULL.getCode())
                        .build();
            }
            Subject subject = iSubjectService.query(subjectId);
            if (ObjectUtils.isEmpty(subject)) {
                //科目不存在
                return ApiResponse.builder()
                        .code(ResponseCode.SUBJECT_EXIST.getCode())
                        .build();
            }
            return ApiResponse.builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .data(subject)
                    .build();
        } catch (Exception e) {
            log.error("# 根据id获取科目异常:", e);
            return ApiResponse.builder()
                    .code(ResponseCode.SUBJECT_QUERY_BY_ID_EXCEPTION.getCode())
                    .build();
        }
    }

    @ApiOperation(
            value = "4.5 根据考试任务id查询科目分页数据",
            notes = "30000:根据考试任务id查询科目分页数据成功; 30127:根据考试任务id查询科目分页数据异常; 30128:考试任务id不能为空"
    )
    @ApiOperationSort(value = 5)
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public ApiResponse<Object> page(PageParam<Subject> pageParam, String taskId, String searchText) {
        log.info("# 根据考试任务id查询科目分页数据参数： {}", taskId);
        try {
            if (StringUtils.isEmpty(taskId)) {
                //考试任务id不能为空
                return ApiResponse.builder()
                        .code(ResponseCode.SUBJECT_TASK_ID_IS_NULL.getCode())
                        .build();
            }
            Page<Subject> page = iSubjectService.pageQuery(pageParam, taskId, searchText);
            return ApiResponse.builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .data(page)
                    .build();
        } catch (Exception e) {
            log.error("# 根据考试任务id查询科目分页数据异常:", e);
            return ApiResponse.builder()
                    .code(ResponseCode.SUBJECT_PAGE_QUERY_BY_ID_EXCEPTION.getCode())
                    .build();
        }
    }

    @ApiOperation(
            value = "4.6 根据科目id删除科目",
            notes = "30000:根据科目id删除科目成功; 30129:根据科目id删除科目异常; 30130:科目id不能为空；30300：科目已绑定批次，不允许变更"
    )
    @ApiOperationSort(value = 6)
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    public ApiResponse<Object> delete(@RequestBody SubjectDeleteParam param) {
        log.info("# 根据科目id删除科目参数： {}", param.getSubjectIds());
        try {
            if (TextUtil.isNull(param.getTaskId())) {
                //任务id不能为空
                return ApiResponse.builder()
                        .code(ResponseCode.SUBJECT_TASK_ID_IS_NULL.getCode())
                        .build();
            }
            if (StringUtils.isEmpty(param.getSubjectIds())) {
                //科目id不能为空
                return ApiResponse.builder()
                        .code(ResponseCode.SUBJECT_ID_IS_NULL.getCode())
                        .build();
            }
            // 检测是否绑定了报名
            iTaskService.checkBindBm(param.getTaskId());
            // 校验任务数据锁定状态(后续版本考虑优化为从缓存中获取状态)
            iTaskService.isLockDataThrowException(param.getTaskId());
            // 检查是否绑定批次
            String ids = iTimeSubjectService.haveTimeSubjectBinding(param.getTaskId(), param.getSubjectIds());
            if (StringUtils.isNotEmpty(ids)) {
                log.error("# 删除科目异常: {}已绑定批次", ids);
                return ApiResponse.builder()
                        .code(ResponseCode.SUBJECT_IS_BIND_FORBID_CHANGE.getCode())
                        .build();
            }
            //校验科目是否存在已报名考生
            if (iCandidateSubjectService.hasCandidateSubject(param.getTaskId(), param.getSubjectIds())) {
                //科目下存在已报名考生
                return ApiResponse.builder()
                        .code(ResponseCode.REGISTERED_CANDIDATES_UNDER_THE_SUBJECT.getCode())
                        .build();
            }
            iSubjectService.delete(param.getSubjectIds());
            return ApiResponse.builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .build();
        } catch (KqException k) {
            log.error("# 根据科目id删除科目业务异常: {}", k.getErrMsg());
            return ApiResponse.builder()
                    .code(k.getErrCode())
                    .data(k.getMessage())
                    .build();
        } catch (Exception e) {
            log.error("# 根据科目id删除科目异常:", e);
            return ApiResponse.builder()
                    .code(ResponseCode.SUBJECT_REMOVE_EXCEPTION.getCode())
                    .build();
        }
    }

    @ApiOperation(
            value = "4.7 查询批次选择的科目",
            notes = "20000:查询批次选择的科目成功; 43040701:查询批次选择的科目异常; 43040702:考试任务id不能为空"
    )
    @ApiOperationSort(value = 5)
    @RequestMapping(value = "/taskTimeSubjectArrange", method = RequestMethod.GET)
    public ApiResponse<Object> taskTimeSubjectArrange(@Valid TaskTimeSubjectArrangeDTO param, BindingResult bindingResult) {
        log.info("# 查询批次选择的科目： {}", param);
        try {
            if (bindingResult.hasErrors()) {
                return ApiResponse.builder()
                        .code(ResponseCode.TIMES_SUBJECT_QUERY_PARAM.getCode())
                        .data(bindingResult.getAllErrors())
                        .build();
            }
            return ApiResponse.builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .data(iSubjectService.taskTimeSubjectArrange(param))
                    .build();
        } catch (Exception e) {
            log.error("查询批次选择的科目，", e);
            return ApiResponse.builder()
                    .code(ResponseCode.TIMES__SUBJECT_QUERY_EXCEPTION.getCode())
                    .build();
        }
    }

    @ApiOperation(
            value = "4.8 批次绑定科目",
            notes = "20000:批次绑定科目成功; 43040801:批次绑定科目异常; 43040802:考试任务id不能为空"
    )
    @ApiOperationSort(value = 5)
    @RequestMapping(value = "/bingTimeSubject", method = RequestMethod.POST)
    public ApiResponse<Object> bingTimeSubject(@Valid @RequestBody TimeSubjectBindingDTO param, BindingResult bindingResult) {
        log.info("# 批次绑定科目： {}", param);
        try {
            User user = getUser();
            //参数校验
            if (Objects.isNull(param) || com.hyt.core.util.StringUtils.isEmpty(param.getTaskId())) {
                return ApiResponse.builder().code(ResponseCode.PARAM_TASK_ID_CAN_NOT_NULL.getCode()).build();
            }
            if (bindingResult.hasErrors()) {
                return ApiResponse.builder()
                        .code(ResponseCode.TIMES_SUBJECT_BINDING_PARAM.getCode())
                        .data(bindingResult.getAllErrors())
                        .build();
            }
            return ApiResponse.builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .data(iSubjectService.bingTimeSubject(param, user))
                    .build();
        } catch (KqException kq) {
            log.error("批次绑定科目，", kq);
            return ApiResponse.builder()
                    .code(kq.getErrCode())
                    .data(kq.getErrMsg())
                    .build();
        } catch (Exception e) {
            log.error("批次绑定科目，", e);
            return ApiResponse.builder()
                    .code(ResponseCode.TIMES__SUBJECT_BINGDING_EXCEPTION.getCode())
                    .build();
        }
    }

    @ApiOperation(
            value = "4.9 导入机构平台科目",
            notes = "20000:导入机构平台科目成功; 43040901:导入机构平台科目信息异常; 43040902:考试任务id不能为空"
    )
    @ApiOperationSort(value = 5)
    @RequestMapping(value = "/importPt", method = RequestMethod.POST)
    public ApiResponse<Object> importPt(@Valid @RequestBody TaskSubjectImportDTO param, BindingResult bindingResult) {
        log.info("# 批次绑定科目： {}", param);
        User user = getUser();
        if (Objects.isNull(user) || Objects.isNull(user.getId())) {
            return ApiResponse.builder()
                    .code(ResponseCode.USER_NOT_LOGIN.getCode())
                    .build();
        }
        try {
            if (bindingResult.hasErrors()) {
                return ApiResponse.builder()
                        .code(ResponseCode.TASK_SUBJECT_BINDING_PARAM.getCode())
                        .data(bindingResult.getAllErrors())
                        .build();
            }
            iSubjectService.importPt(param, user);
            return ApiResponse.builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .build();
        } catch (KqException kq) {
            log.error("批次绑定科目，", kq);
            return ApiResponse.builder()
                    .code(kq.getErrCode())
                    .data(kq.getErrMsg())
                    .build();
        } catch (Exception e) {
            log.error("批次绑定科目，", e);
            return ApiResponse.builder()
                    .code(ResponseCode.TASK_SUBJECT_BINGDING_EXCEPTION.getCode())
                    .build();
        }
    }

    @ApiOperation(value = "4.10 下载导入考试科目模板", notes = "20000:成功,43041001：下载导入考试科目模板失败,")
    @ApiOperationSort(value = 10)
    @GetMapping(value = "/downExamSubjectTemplate")
    public ApiResponse<?> downExamSubjectTemplate(HttpServletResponse response) {
        ExcelWriter writer = null;
        try {
            // 获取当前登录人的机构id
            User user = getUser();
            if (null == user || StrUtil.isEmptyIfStr(user.getId())) {
                return ApiResponse.builder().code(ResponseCode.USER_NOT_LOGIN.getCode()).build();
            }
            // 获取所有的考场类型
            //List<ExamRoomTypeVo> examRoomTypeVos = iSubjectService.queryExamRoomTYpes(user);

            String fileName = URLEncoder.encode("导入科目模板", "UTF-8");
            response.setContentType("application/vnd.ms-excel");
            response.setCharacterEncoding("utf-8");
            response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
            ClassPathResource resource = new ClassPathResource("templates/subject/subject.xlsx");
            ServletOutputStream out = response.getOutputStream();
            writer = EasyExcel.write(out).withTemplate(resource.getInputStream()).build();
            WriteSheet sheet1 = EasyExcel.writerSheet(0).build();
            //WriteSheet sheet2 = EasyExcel.writerSheet(1).build();
            //机构层级
            List<List<String>> deptList = iTaskRoomService.getDeptData(user);
            //获取任务区域
            //List<OfficeAreaSheet> areaSheets = iSubjectService.getOfficeAreaSheet();
            writer.write(deptList, sheet1);
            //writer.write(areaSheets,sheet2);

            return ApiResponse.builder().code(20000).build();
        } catch (Exception e) {
            log.error("# 下载导入考试科目模板异常", e);
            return ApiResponse.builder().code(43041001).build();
        } finally {
            if (Objects.nonNull(writer)) {
                writer.finish();
            }
        }
    }

    @ApiOperation(value = "4.11 导入科目信息", notes = "20000:成功,43041101：导入考试科目模板失败,")
    @ApiOperationSort(value = 11)
    @PostMapping(value = "/importSubject")
    @Log(module = "考务科目管理", business = "导入科目信息")
    @ProgressAnno(total = 100, timeoutSeconds = 60 * 20, errorCode = 43041101, canConcurrent = false, lockKeyCreator = CommonLockKeyCreator.class)
    public void importSubject(@RequestParam String fileUrl, @RequestParam String taskId) throws Exception {
        // 获取当前登录人的机构id
        User user = getUser();
        if (null == user || StrUtil.isEmptyIfStr(user.getId())) {
            BusinessLogicException.throwException(ResponseCode.USER_NOT_LOGIN.getCode());
        }
        iSubjectService.importSubject(fileUrl, taskId, user);

    }

    @ApiOperation(
            value = "4.12 查询平台科目 -- 确认后删除",
            notes = "20000:查询平台科目成功; 43040901:查询平台科目信息异常; 43040902:考试任务id不能为空"
    )
    @ApiOperationSort(value = 5)
    @RequestMapping(value = "/queryFromPt", method = RequestMethod.GET)
    public ApiResponse<Page<ExamSubjectDTO>> queryFromPt(PageParam<Subject> pageParam, @RequestParam ExamSubjectParam param) {
        log.info("# 查询平台科目： {}", param);
        User user = getUser();
        if (Objects.isNull(user) || Objects.isNull(user.getId())) {
            return ApiResponse.<Page<ExamSubjectDTO>>builder()
                    .code(ResponseCode.USER_NOT_LOGIN.getCode())
                    .build();
        }
        if (null == param.getTaskId()) {
            return ApiResponse.<Page<ExamSubjectDTO>>builder()
                    .code(ResponseCode.TASK_SUBJECT_BINDING_PARAM.getCode())
                    .build();
        }
        try {
            return ApiResponse.<Page<ExamSubjectDTO>>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .data(iSubjectService.queryFromPt(pageParam, param, user))
                    .build();
        } catch (KqException kq) {
            log.error("查询平台科目，", kq);
            return ApiResponse.<Page<ExamSubjectDTO>>builder()
                    .code(kq.getErrCode())
                    .build();
        } catch (Exception e) {
            log.error("查询平台科目，", e);
            return ApiResponse.<Page<ExamSubjectDTO>>builder()
                    .code(ResponseCode.TASK_SUBJECT_BINGDING_EXCEPTION.getCode())
                    .build();
        }
    }

    @ApiOperation(
            value = "4.13 查询任务绑定的科目id",
            notes = "20000:查询平台科目成功; 43040901:查询平台科目信息异常; 43040902:考试任务id不能为空"
    )
    @ApiOperationSort(value = 5)
    @RequestMapping(value = "/queryTaskSubject", method = RequestMethod.GET)
    public ApiResponse<Object> queryTaskSubject(@RequestParam String taskId) {
        log.info("# 查询任务绑定的科目id： {}", taskId);
        User user = getUser();
        if (Objects.isNull(user) || Objects.isNull(user.getId())) {
            return ApiResponse.builder()
                    .code(ResponseCode.USER_NOT_LOGIN.getCode())
                    .build();
        }
        try {
            return ApiResponse.builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .data(iSubjectService.queryTaskSubject(taskId, user))
                    .build();
        } catch (KqException kq) {
            log.error("查询任务绑定的科目id，", kq);
            return ApiResponse.builder()
                    .code(kq.getErrCode())
                    .build();
        } catch (Exception e) {
            log.error("查询任务绑定的科目id，", e);
            return ApiResponse.builder()
                    .code(ResponseCode.TASK_SUBJECT_QUERY_ERROR.getCode())
                    .build();
        }
    }

}
